package com.codedancer.campus.enums;

import cn.hutool.core.util.ObjectUtil;
import com.codedancer.campus.common.enums.CodeStringEnum;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @Author codeworld 排序类型
 **/
public enum OrderType implements CodeStringEnum {

    DEFAULT("default", "默认排序"),
    TIME_DESC("timeDesc", "时间降序"),
    TIME_ASC("timeAsc", "时间升序"),
    NEW("new", "最新"),
    HOT("hot", "最热");

    /**
     * 对应的值
     */
    @JsonValue
    private final String value;

    /**
     * 对应的名称
     */
    private final String name;

    OrderType(String value, String name) {
        this.value = value;
        this.name = name;
    }

    public static OrderType fromValue(Integer value) {
        for (OrderType orderType : OrderType.values()) {
            if (ObjectUtil.equal(orderType.getValue(), value)) {
                return orderType;
            }
        }
        return null;
    }

    @Override
    public String getValue() {
        return value;
    }

    public String getName() {
        return name;
    }
}
